package myjava.closures;

public class StudingClosures {

   public static void main(String[] args) {
      // generation and usage of the closure
      Answerer closure = create(42, true);
      closure.answer();
   }

   static private Answerer create(final int answer, boolean isPolite) {

      Answerer o = null;

      if (isPolite) {
         o = new Answerer() {

            @Override
            public void answer() {
               System.out.println("I'll answer politely! I am happy to announce the answer is: " + answer);
            }
         };
      } else {
         o = new Answerer() {

            @Override
            public void answer() {
               System.out.println("I'll answer reduly! " + answer + " for fuck's sake!");
            }
         };
      }
      return o;
   }
}